package com.gticket.customerbackend.handler;

import com.gticket.customerbackend.pojo.Cinema;
import com.gticket.customerbackend.pojo.ResponseDate;
import com.gticket.customerbackend.service.CinemaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 影院cinema的控制层
 */
@RestController
@Data
@Api(value = "后台影院信息设置")
@RequestMapping("/cinema")
public class CinemaHandler {
    @Autowired
    private  CinemaService cinemaService;
    /**
     * 展示影院信息
     * @param
     * @return 影院cinema信息
     */
    @ApiOperation(value = "获取cinemas",notes = "")
    @GetMapping
//    @Cacheable(value = "cinemas",keyGenerator = "myKeyGenerator")
    public ResponseDate listCinemas(){
        ResponseDate responseDate=new ResponseDate();
        Cinema cinema=new Cinema();
        try {
            List<Cinema> cinemas= cinemaService.listCinemas(cinema);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(cinemas);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }

    @ApiOperation(value = "通过cinema_id获取cinema",notes = "")
    @GetMapping(value = "/id")
//    @Cacheable(value = "cinema",keyGenerator = "myKeyGenerator")
    public ResponseDate getCinemaByCinema_id(Cinema cinema){
        ResponseDate responseDate=new ResponseDate();
        try {
            List<Cinema> cinemas= cinemaService.listCinemas(cinema);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(cinemas);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }

}
